﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem.Ajax.ASP.Game
{
    public partial class edited_crossword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string request = Request.Form["request"];
            string[] split = request.Split(',');
            int id = int.Parse(split[0]);
            string name = split[1];
            int vertical = int.Parse(split[2]);
            int horizontal = int.Parse(split[3]);
            string primary_question = split[4];
            int primary_hor = int.Parse(split[5]);
            string[] ver_question = new string[vertical];
            string[] ver_word = new string[vertical * horizontal];

            int z = 0;
            for (int i = 6; i < 6 + vertical; i++)
            {
                ver_question[z] = split[i];
                z++;
            }
            z = 0;
            for (int i = 6 + vertical; i < split.Length - 1; i++)
            {
                ver_word[z] = split[i];
                z++;
            }
            new TblCrossWordQuestionController().Update(id,name, vertical, horizontal, primary_question, primary_hor);

            var get_question = new TblCrossWordDetailsQuestionController().FetchAll().Where(x => x.CrossWordId == id).ToList();
            for (int i = 0; i < vertical; i++)
            {
                string[] split2 = ver_question[i].Split('_');
                int ver = int.Parse(split2[0]);
                string ques = split2[1];
                new TblCrossWordDetailsQuestionController().Update(get_question[i].Id,id, ver, ques);
            }

            var get_word = new TblCrossWordDetailsWordController().FetchAll().Where(x => x.CrosswordId == id).ToList();
            for (int i = 0; i < vertical * horizontal; i++)
            {
                string[] split2 = ver_word[i].Split('_');
                int ver = int.Parse(split2[0]);
                int hor = int.Parse(split2[1]);
                string word = split2[2];
                new TblCrossWordDetailsWordController().Update(get_word[i].Id,id, ver, hor, word);
            }
        }
    }
}